import * as React from "react";
import { inject, observer } from "mobx-react";
import { AppStore } from "../store";
import { Switch, Route, Redirect } from 'react-router-dom';
import { Spin } from 'antd';
import { HubConnectionBuilder } from '@aspnet/signalr';
import { Routes } from '../basicData/routes'
import { CommonData } from '../basicData/data'
import './app.less'
import { listenECodePlatform } from '../util/util';
import { userInfo } from '../basicData/api'
import ls from '../util/localStorage'

interface IProps {
  appStore: AppStore;
  location: { hash: string, pathname: string, search: string, state: object };
  children?: AudioContextLatencyCategory;
}

@inject("appStore")
@observer
class App extends React.Component<IProps, {}> {

  componentWillMount() {
    listenECodePlatform()
  }

  render() {
    return (
      top.location !== location
      ? 
      <div> 权限平台 </div>
      :
      <Spin spinning={this.props.appStore.isLoading} tip="加载中。。。">
        <iframe id='iframe' src={CommonData.QRCodeURL[process.env.NODE_ENV]} style={{ "display": "none" }}></iframe>
        <Switch>
          {Routes.map(
            (item: { exact: boolean, path: string, component: any },
              index: number
            ) => (
                <Route
                  key={index}
                  exact={item.exact}
                  path={item.path}
                  component={item.component}
                />
              ))}
          {this.props.location.pathname === '/'
            ? <Redirect to="home" /> : <Redirect to="notFound" />}
        </Switch>
      </Spin>
    );
  }
}

export default App